package com.xinyue.game.server.logic.handler;


import com.xinyue.game.server.logic.handler.command.LoadRoleCommand;
import com.xinyue.game.server.logic.service.PlayerService;
import com.xinyue.game.service.framwork.context.GameUserChannelContext;
import com.xinyue.game.service.framwork.mapping.GameHandlerComponent;
import com.xinyue.game.service.framwork.mapping.GameRequestMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 王广帅
 * @since 2023/7/6 20:35
 **/
@GameHandlerComponent("game-server")
public class GameHandler {
    private Logger logger = LoggerFactory.getLogger(GameHandler.class);

    @Autowired
    private PlayerService playerService;

    @GameRequestMapping(requestUri = "loadRole")
    public void loadRole(GameUserChannelContext context) {
        logger.debug("收到请求:{}", context.getHeader().getRequestUri());
        LoadRoleCommand.LoadRoleRequest request = context.getRequestBody(LoadRoleCommand.LoadRoleRequest.class);
        LoadRoleCommand.PlayerModel playerModel = playerService.getPlayerModel(request.getUserId(), request.getPlayerId(), request.getZoneId());
        LoadRoleCommand.LoadRoleResponse response = new LoadRoleCommand.LoadRoleResponse();
        response.setRole(playerModel);
        context.response(response);
    }
}
